package com.coder.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.util.UrlPathHelper;

import com.alibaba.druid.Constants;

/**
 * HttpServletRequest帮助类
 */
public class RequestUtils {
	private static final Logger log = LoggerFactory.getLogger(RequestUtils.class);

	private static Map<String, String> getRequestMap(HttpServletRequest request, String prefix,
			boolean nameWithPrefix) {
		Map<String, String> map = new HashMap<String, String>();
		Enumeration<String> names = request.getParameterNames();
		String name, key, value;
		while (names.hasMoreElements()) {
			name = names.nextElement();
			if (name.startsWith(prefix)) {
				key = nameWithPrefix ? name : name.substring(prefix.length());
				value = StringUtils.join(request.getParameterValues(name), ',');
				map.put(key, value);
			}
		}
		return map;
	}

	public static Map<String, String> getSignMap(HttpServletRequest request) {
		Map<String, String> param = new HashMap<String, String>();
		@SuppressWarnings("rawtypes")
		Enumeration penum = (Enumeration) request.getParameterNames();
		while (penum.hasMoreElements()) {
			String pKey = (String) penum.nextElement();
			String value = request.getParameter(pKey);
			// sign和uploadFile不参与 值为空也不参与
			if (!pKey.equals("sign") && !pKey.equals("uploadFile") && StringUtils.isNotBlank(value)) {
				param.put(pKey, value);
			}
		}
		return param;
	}
}
